import React, { useEffect } from 'react'
import { Modal, Form, InputNumber, message } from 'antd'
import style from './Index.module.less'
import { addRequest } from './ajax'
import { awaitWrap } from '@src/assets/js/tool'

async function addHandle (data, callback) {
  const h = message.loading('提交中', 120)
  const [e] = await awaitWrap(addRequest(data))
  h()
  if (e === null) {
    callback()
  }
}

const { Item, useForm } = Form

function Main ({ visible, hide, refreshFn }) {
  const [formRef] = useForm()
  useEffect(() => {
    if (formRef && visible) {
      formRef.resetFields()
    }
  }, [visible, formRef])
  return (
    <Modal open={visible} title='新增上报' forceRender onCancel={() => hide()} onOk={() => formRef.submit()}>
      <Form form={formRef} labelCol={{ flex: '108px' }} onFinish={d => addHandle(d, () => { hide(); refreshFn() })}>
        <Item label='年份' name='year'>
          <InputNumber placeholder='请输入' min={2000} precision={0} className={style.full} />
        </Item>
        <Item label='受理案件总数' name='case_accecpt_num'>
          <InputNumber placeholder='请输入' addonAfter='件' min={0} precision={0} className={style.full} />
        </Item>
        <Item label='标的总额' name='case_collection_amount'>
          <InputNumber placeholder='请输入' addonAfter='万元' min={0} className={style.full} />
        </Item>
        <Item label='调解和解案件数' name='case_mediate_count'>
          <InputNumber placeholder='请输入' addonAfter='件' min={0} precision={0} className={style.full} />
        </Item>
        <Item label='网上仲裁案件数' name='case_arbitra_online_num'>
          <InputNumber placeholder='请输入' addonAfter='件' min={0} precision={0} className={style.full} />
        </Item>
        <Item label='涉外案件数' name='case_sw_num'>
          <InputNumber placeholder='请输入' addonAfter='件' min={0} precision={0} className={style.full} />
        </Item>
        <Item label='撤销案件数' name='case_cancel_num'>
          <InputNumber placeholder='请输入' addonAfter='件' min={0} precision={0} className={style.full} />
        </Item>
        <Item label='不予执行案件数' name='case_not_carry_num'>
          <InputNumber placeholder='请输入' addonAfter='件' min={0} precision={0} className={style.full} />
        </Item>
        <Item label='重新仲裁案件数' name='case_rejudgment_num'>
          <InputNumber placeholder='请输入' addonAfter='件' min={0} precision={0} className={style.full} />
        </Item>
      </Form>
    </Modal>
  )
}

export default Main
